﻿package  encrypt{
	
	public class JsonParse {

		private var loginSuccess:Boolean;
		
		public function JsonParse() {
			// constructor code
		}
		
		public function loginResult(input:String):Array{
			var stt:int = input.indexOf("ok");
			if(stt == -1){
				var output:Array = new Array();
				var jsonLogin = JSON.parse(input);
				var reason = jsonLogin.error;
				output.push(reason);
				var error_code = jsonLogin.error_code;
				output.push(error_code);
				return output;
			}else{
				var jsonLogin = JSON.parse(input);
				trace(jsonLogin);
				var results1:Array = jsonLogin.ok;
				trace(results1[0]);
				return results1;
			}
		}
		
		public function registerResult(input:String):Array{
			var stt:int = input.indexOf("ok");
			if(stt == -1){
				var jsonReg = JSON.parse(input);
				var reReg:Array = jsonReg.error;
				return reReg;
			}else{
				var jsonRegister = JSON.parse(input);
				var reReg:Array = jsonRegister.ok;
				return reReg;
			}
		}
		
		
		public function startSession(input:String):Array{
			var output:Array = new Array();
			var jsonStartSession = JSON.parse(input);
			output = jsonStartSession;
			trace("Dau ra cua bat dau phien la: N = " + output[0]+" e = "+output[1]);
			var NStr:String = output[0];
			var stt:int = NStr.indexOf("L");
			if(stt != -1){
				NStr = NStr.replace("L","");
			}
			var N:Number = Number(NStr);
			trace("So N = "+N);
			var e:uint = uint(output[1]);
			trace(e);
			var session:Array = new Array();
			session.push(N);
			session.push(e);
			return session;
		}
		
		public function parsePersonalInformation(input:String):Array{
			var stt:int = input.indexOf("ok");
			if(stt == -1){
				return null;
			}else{
				var jsonPersonalInf = JSON.parse(input);
				var rePerInf:Array = jsonPersonalInf.ok;
				trace(rePerInf);
				return rePerInf;
			}
		}
		
		

	}
	
}
